program rainbow;

var  pal:array [0..199,0..2] of byte;
     p : word;
     headptr:word absolute $40:$1A;
     tailptr:word absolute $40:$1C;

begin
  for p:=0 to 49 do begin
    pal[p,0]:=p;
    pal[p,1]:=49-p;
    pal[p,2]:=0;

    pal[p+50,0]:=49-p;
    pal[p+50,1]:=0;
    pal[p+50,2]:=p;

    pal[p+100,0]:=0;
    pal[p+100,1]:=p;
    pal[p+100,2]:=49;

    pal[p+150,0]:=0;
    pal[p+150,1]:=49-p;
    pal[p+150,2]:=49-p;
  end;

  repeat
    inline($FA);
    repeat until (port[$3DA] and 8)>0;
    repeat until (port[$3DA] and 8)=0;

    for p:= 0 to 198 do begin
      repeat until (port[$3DA] and 1)>0;
      port[$3C8]:=0;
      port[$3C9]:=pal[p,0];
      port[$3C9]:=pal[p,1];
      port[$3C9]:=pal[p,2];
      repeat until (port[$3DA] and 1)=0;
      repeat until (port[$3DA] and 1)>0;
      repeat until (port[$3DA] and 1)=0;
    end;

    port[$3C8]:=0;
    port[$3C9]:=0;port[$3C9]:=0;port[$3C9]:=0;
    inline($FB);
  until headptr<>tailptr;
  headptr:=tailptr
end.
